function updateSequence(inputFile)

d=1;
triangleFile='../finalData/hw4.edges';
propertyFile='property_new.txt';

set_cvx;

[sites, edges, triangles]=readTriangles(triangleFile);
siteGrid=createSiteGrid(sites);
triangleGrid=createTriangleGrid(sites,triangles);


%parse the input
[oldSequenceFile, newSequenceFile, currPos, currPos_seq, currPos_tour, ...
    newTourSites, newTourIdx]=readInput(inputFile);

oldSequence=load(oldSequenceFile);
numOldSeq=size(oldSequence,1);

%find corresondence between old tour and old seqeunces
%oldSequence(oldSeqIdx(t))=
%oldTourIdx=1:currPos_tour;
oldTourIdx=newTourIdx(newTourIdx~=0);
oldSeqIdx=zeros(size(oldTourIdx));

%assign oldSeqIdx for visited newTourIdx (not added or deleted)
tourIdx=min(newTourIdx(newTourIdx>0));
if tourIdx==1
    tourIdx=tourIdx+1;
end
tour=newTourSites(newTourIdx==tourIdx,:);
for n=1:2:numOldSeq
    if passSight(oldSequence(n,:)',tour',d)
        oldSeqIdx(oldTourIdx==tourIdx)=n;
        tourIdx=min(newTourIdx(newTourIdx>tourIdx));
        if isempty(tourIdx) %visited all sequences
            break;
        end
        tour=newTourSites(newTourIdx==tourIdx,:);
    end
end


% find delta_min (minimum distance to terrain)
delta_min=findDelta(sites, newTourSites)-d;
sites(:,3)=sites(:,3)+delta_min;


startingT=find(newTourIdx==currPos_tour)+1;
t=startingT;

newSequence=oldSequence(currPos_seq:(currPos_seq+2),:)';

while t<=length(newTourIdx)
    currT=newTourIdx(t-1);
    nextT=newTourIdx(t);
    if currT+1==nextT
        %copy the existing sequence
        currPos_seq=max(currPos_seq+2,oldSeqIdx(currT==oldTourIdx));
        newSequence=[newSequence, oldSequence((currPos_seq+1):oldSeqIdx(nextT==oldTourIdx),:)'];
    else
        tour1=newSequence(:,end);
        prev=newSequence(:,end-1);  
        v=tour1-prev;
        prev=tour1+v./norm(v); %change sign
        if nextT==0 %new path added
            tour2=newTourSites(t,:)';
            after=[];
        else
            seqIdx=oldSeqIdx(nextT==oldTourIdx)-1;
            after=oldSequence(seqIdx,:)';
            tour2=oldSequence((seqIdx+1),:)';
            v=after-tour2; %keep the sign
            after=tour2+v./norm(v);
        end
        guess=(tour1+tour2)./2;
        localSequence=findLocalSequence(prev, tour1, guess, tour2, after, d, sites, triangles, triangleGrid);
        newSequence=[newSequence, localSequence(:,3:(end-1))];
    end
    t=t+1;
end

%totalSequence=[[0;0;0], newSequence, [0;0;0]];
%drawTrajectory(3,totalSequence, sites);

[finalSequence, passingIdx]=examineCurve(newSequence, d, delta_min, newTourSites(startingT:end,:), sites, triangles, triangleGrid, propertyFile);
totalSequence=[[0;0;0],finalSequence, [0;0;0]];
writeOutput(newSequenceFile, totalSequence);

end